using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.IO;
using YukiFX5017.Core;

namespace YukiFX5017
{
    public class DataBase
    {
        public static string DBPath = @"C:\Documents and Settings\" + Environment.UserName + @"\Desktop\Testing\Database";
        public static Ini Stats = new Ini(DBPath + @"\Stats.ini");
        public static ushort[][] Portals;
        public static uint[][] NPCs;
        public static uint[][] Items;
        public static string[][] DBPlusInfo;
        public static string[][] Mobs;
        public static uint[][] MobSpawns;
        public static uint ExpRate;
        public static uint ProfExpRate;
        public static ushort[][] RevPoints;
        public static ushort[] NoPKMaps = new ushort[] { 1002, 1039, 1036, 1010, 500, 1004, 700 };
        public static ushort[] PKMaps = new ushort[] { 1038, 1080, 1090 };
        public Hashtable Skills = new Hashtable();
        public static ushort[][][] SkillAttributes = new ushort[9000][][];
        public static Hashtable SkillsDone = new Hashtable();
        public static ushort GC1X = 530;
        public static ushort GC1Y = 556;
        public static ushort GC1Map = 1075;
        public static ushort GC2X = 10;
        public static ushort GC2Y = 90;
        public static ushort GC2Map = 1080;
        public static ushort GC3X = 116;
        public static ushort GC3Y = 164;
        public static ushort GC3Map = 1090;
        public static ushort GC4X = 43;
        public static ushort GC4Y = 75;
        public static ushort GC4Map = 1099;
        public static string[] ForbiddenNames = new string[] { "GM", "PM", "GameMaster", "Administrator", "BigVaginaFace" };

        public static void ChangeOnlineStatus(string AccName, byte To)
        {
            lock (SyncedSave)
            {
                SyncedSave.FileName = DBPath + @"\Accounts\\" + AccName + ".ini";
                SyncedSave.Write("Account", "Online", "0");
            }
        }
        public static void AllOffline()
        {
            string[] Data = Directory.GetFiles(DBPath + @"\Accounts", "*.ini");
            for (int x = 0; x < Data.Length; x++)
            {
                lock (SyncedSave)
                {
                    SyncedSave.FileName = System.Windows.Forms.Application.StartupPath + Data[x];
                    SyncedSave.Write("Account", "Online", "0");
                }
            }
        }
        public static void Ban(string Acc)
        {
            lock (SyncedSave)
            {
                SyncedSave.FileName = DBPath + @"\Accounts\\" + Acc + ".ini";
                SyncedSave.Write("Account", "Ban", "1");
            }
        }

        public static void SaveGuild(Guild TheGuild)
        {
            string PackedDLs = "";

            foreach (DictionaryEntry DE in TheGuild.DLs)
            {
                string dl = (string)DE.Value;
                PackedDLs += dl + "~";
            }
            if (PackedDLs.Length > 0)
                PackedDLs = PackedDLs.Remove(PackedDLs.Length - 1, 1);

            string PackedMembers = "";

            foreach (DictionaryEntry DE in TheGuild.Members)
            {
                string nm = (string)DE.Value;
                PackedMembers += nm + "~";
            }
            if (PackedMembers.Length > 0)
                PackedMembers = PackedMembers.Remove(PackedMembers.Length - 1, 1);

            string PackedAllies = "";

            foreach (string ally in TheGuild.Allies)
            {
                PackedAllies += ally + "~";
            }
            if (PackedAllies.Length > 0)
                PackedAllies = PackedAllies.Remove(PackedAllies.Length - 1, 1);

            string PackedEnemies = "";

            foreach (string enemy in TheGuild.Enemies)
            {
                PackedEnemies += enemy + "~";
            }
            if (PackedEnemies.Length > 0)
                PackedEnemies = PackedEnemies.Remove(PackedEnemies.Length - 1, 1);

            byte Pole = 0;

            if (TheGuild.HoldingPole)
                Pole = 1;

            //`Guilds` SET `Fund` = " + TheGuild.Fund + ",
            //`GuildLeader` = '" + TheGuild.Creator + "',
            //`MembersCount` = " + TheGuild.MembersCount + ", 
            //`GWWins` = " + TheGuild.GWWins + ", 
            //`HoldingPole` = " + Pole + ",
            //`Bulletin` = '" + TheGuild.Bulletin + "',
            //`DLs` = '" + PackedDLs + "',
            //`NormalMembers` = '" + PackedMembers + "',
            //`Allies` = '" + PackedAllies + "',
            //`Enemies` = '" + PackedEnemies + "' 
            //WHERE `GuildID` = " + TheGuild.GuildID,
            throw new NotImplementedException();
        }

        public static void DisbandGuild(ushort GUID)
        {
                //"DELETE FROM `Guilds` WHERE `GuildID` = " + GUID,
            throw new NotImplementedException();
        }

        public static void NoGuild(uint UID)
        {
           // "UPDATE `Characters` 
           //`GuildPos` = 0,
           //     `MyGuild` = 0,
           // `GuildDonation` = 0 
           // WHERE `UID` = " + UID
            throw new NotImplementedException();
        }
        public static bool NewGuild(ushort GuildID, string GuildName, Character Creator)
        {
            try
            {
                //"INSERT INTO guilds 
                //    (GuildID,
                //    GuildName,
                //    Fund,
                //    GuildLeader,
                //    MembersCount,
                //    DLs,
                //    NormalMembers,
                //    Allies,
                //    Enemies,
                //    GWWins,
                //    HoldingPole,
                //    Bulletin
                //    ) VALUES
                //   GuildID + ",
                // GuildName + "',
                //1000000,
                //Creator.Name 
                //Creator.UID.ToString()
                //Creator.Level.ToString()
                //1000000'
                //,1,
                //'',
                //'',
                //'',
                //''
                //,0,
                //0,
                //'New guild'
                throw new NotImplementedException();
                return true;
            }
            catch { throw new NotImplementedException(); return false; }
        }

        public enum SkillType : ushort
        {
            RangeSkillMelee = 0,
            RangeSkillRanged = 1,
            SingleTargetSkillMagic = 2,
            TargetRangeSkillMagic = 3,
            DirectSkillMelee = 4,
            RangeSectorSkillRanged = 5,
            SingleTargetSkillMagicHeal = 6,
            SelfUseSkill = 7,
            BuffSkill = 8,
            RangeSkillHeal = 11,
            SingleTargetSkillMelee = 12,
            SingleTargetSkillRanged = 13
        }

        public static void DefineSkills()
        {
            //SkillType Range Sector Damage/Heal CostMana/Stamina ActivationChance
            SkillAttributes[1045] = new ushort[5][];
            SkillAttributes[1045][0] = new ushort[6] { 4, 5, 0, 0, 20, 0 };
            SkillAttributes[1045][1] = new ushort[6] { 4, 6, 0, 0, 20, 0 };
            SkillAttributes[1045][2] = new ushort[6] { 4, 7, 0, 0, 20, 0 };
            SkillAttributes[1045][3] = new ushort[6] { 4, 8, 0, 0, 20, 0 };
            SkillAttributes[1045][4] = new ushort[6] { 4, 9, 0, 0, 20, 0 };
            SkillsDone.Add(1045, 4);

            SkillAttributes[1046] = new ushort[5][];
            SkillAttributes[1046][0] = new ushort[6] { 4, 5, 0, 0, 20, 0 };
            SkillAttributes[1046][1] = new ushort[6] { 4, 6, 0, 0, 20, 0 };
            SkillAttributes[1046][2] = new ushort[6] { 4, 7, 0, 0, 20, 0 };
            SkillAttributes[1046][3] = new ushort[6] { 4, 8, 0, 0, 20, 0 };
            SkillAttributes[1046][4] = new ushort[6] { 4, 9, 0, 0, 20, 0 };
            SkillsDone.Add(1046, 4);

            SkillAttributes[1120] = new ushort[4][];
            SkillAttributes[1120][0] = new ushort[6] { 1, 7, 0, 540, 0, 0 };
            SkillAttributes[1120][1] = new ushort[6] { 1, 7, 0, 650, 0, 0 };
            SkillAttributes[1120][2] = new ushort[6] { 1, 11, 0, 720, 0, 0 };
            SkillAttributes[1120][3] = new ushort[6] { 1, 11, 0, 770, 0, 0 };
            SkillsDone.Add(1120, 3);

            SkillAttributes[1115] = new ushort[5][];
            SkillAttributes[1115][0] = new ushort[6] { 0, 2, 0, 35, 30, 0 };
            SkillAttributes[1115][1] = new ushort[6] { 0, 2, 0, 35, 30, 0 };
            SkillAttributes[1115][2] = new ushort[6] { 0, 3, 0, 35, 30, 0 };
            SkillAttributes[1115][3] = new ushort[6] { 0, 4, 0, 40, 30, 0 };
            SkillAttributes[1115][4] = new ushort[6] { 0, 4, 0, 40, 30, 0 };
            SkillsDone.Add(1115, 4);

            SkillAttributes[7020] = new ushort[10][];
            SkillAttributes[7020][0] = new ushort[6] { 0, 2, 0, 110, 0, 20 };
            SkillAttributes[7020][1] = new ushort[6] { 0, 2, 0, 110, 0, 23 };
            SkillAttributes[7020][2] = new ushort[6] { 0, 2, 0, 110, 0, 26 };
            SkillAttributes[7020][3] = new ushort[6] { 0, 2, 0, 110, 0, 29 };
            SkillAttributes[7020][4] = new ushort[6] { 0, 2, 0, 140, 0, 31 };
            SkillAttributes[7020][5] = new ushort[6] { 0, 2, 0, 140, 0, 34 };
            SkillAttributes[7020][6] = new ushort[6] { 0, 2, 0, 140, 0, 37 };
            SkillAttributes[7020][7] = new ushort[6] { 0, 2, 0, 140, 0, 40 };
            SkillAttributes[7020][8] = new ushort[6] { 0, 2, 0, 140, 0, 43 };
            SkillAttributes[7020][9] = new ushort[6] { 0, 2, 0, 145, 0, 45 };
            SkillsDone.Add(7020, 9);

            SkillAttributes[5010] = new ushort[10][];
            SkillAttributes[5010][0] = new ushort[6] { 0, 2, 0, 110, 0, 20 };
            SkillAttributes[5010][1] = new ushort[6] { 0, 2, 0, 110, 0, 23 };
            SkillAttributes[5010][2] = new ushort[6] { 0, 2, 0, 110, 0, 26 };
            SkillAttributes[5010][3] = new ushort[6] { 0, 2, 0, 110, 0, 29 };
            SkillAttributes[5010][4] = new ushort[6] { 0, 3, 0, 140, 0, 31 };
            SkillAttributes[5010][5] = new ushort[6] { 0, 3, 0, 140, 0, 34 };
            SkillAttributes[5010][6] = new ushort[6] { 0, 3, 0, 140, 0, 37 };
            SkillAttributes[5010][7] = new ushort[6] { 0, 3, 0, 140, 0, 40 };
            SkillAttributes[5010][8] = new ushort[6] { 0, 3, 0, 140, 0, 43 };
            SkillAttributes[5010][9] = new ushort[6] { 0, 3, 0, 145, 0, 45 };
            SkillsDone.Add(5010, 9);

            SkillAttributes[1002] = new ushort[4][];
            SkillAttributes[1002][0] = new ushort[6] { 2, 0, 0, 505, 0, 0 };
            SkillAttributes[1002][1] = new ushort[6] { 2, 0, 0, 666, 0, 0 };
            SkillAttributes[1002][2] = new ushort[6] { 2, 0, 0, 882, 0, 0 };
            SkillAttributes[1002][3] = new ushort[6] { 2, 0, 0, 1166, 0, 0 };
            SkillsDone.Add(1002, 3);

            SkillAttributes[1005] = new ushort[5][];
            SkillAttributes[1005][0] = new ushort[6] { 6, 0, 0, 20, 0, 0 };
            SkillAttributes[1005][1] = new ushort[6] { 6, 0, 0, 70, 0, 0 };
            SkillAttributes[1005][2] = new ushort[6] { 6, 0, 0, 150, 0, 0 };
            SkillAttributes[1005][3] = new ushort[6] { 6, 0, 0, 270, 0, 0 };
            SkillAttributes[1005][4] = new ushort[6] { 6, 0, 0, 400, 0, 0 };
            SkillsDone.Add(1005, 4);

            SkillAttributes[1165] = new ushort[4][];
            SkillAttributes[1165][0] = new ushort[6] { 3, 3, 0, 180, 0, 0 };
            SkillAttributes[1165][1] = new ushort[6] { 3, 3, 0, 240, 0, 0 };
            SkillAttributes[1165][2] = new ushort[6] { 3, 3, 0, 310, 0, 0 };
            SkillAttributes[1165][3] = new ushort[6] { 3, 3, 0, 400, 0, 0 };
            SkillsDone.Add(1165, 3);

            SkillAttributes[8001] = new ushort[6][];
            SkillAttributes[8001][0] = new ushort[6] { 5, 9, 45, 50, 0, 0 };
            SkillAttributes[8001][1] = new ushort[6] { 5, 10, 60, 55, 0, 0 };
            SkillAttributes[8001][2] = new ushort[6] { 5, 11, 80, 60, 0, 0 };
            SkillAttributes[8001][3] = new ushort[6] { 5, 12, 100, 65, 0, 0 };
            SkillAttributes[8001][4] = new ushort[6] { 5, 13, 150, 70, 0, 0 };
            SkillAttributes[8001][5] = new ushort[6] { 5, 14, 180, 72, 0, 0 };
            SkillsDone.Add(8001, 5);

            SkillAttributes[1025] = new ushort[1][];
            SkillAttributes[1025][0] = new ushort[6] { 7, 0, 0, 0, 0, 0 };
            SkillsDone.Add(1025, 0);

            SkillAttributes[1110] = new ushort[1][];
            SkillAttributes[1110][0] = new ushort[6] { 7, 0, 0, 0, 0, 0 };
            SkillsDone.Add(1110, 0);

            SkillAttributes[8030] = new ushort[1][];
            SkillAttributes[8030][0] = new ushort[6] { 14, 8, 0, 100, 0, 1 };
            SkillsDone.Add(8030, 0);

            SkillAttributes[1015] = new ushort[1][];
            SkillAttributes[1015][0] = new ushort[6] { 7, 0, 0, 0, 0, 1 };
            SkillsDone.Add(1015, 0);

            SkillAttributes[8002] = new ushort[1][];
            SkillAttributes[8002][0] = new ushort[6] { 7, 0, 0, 0, 0, 0 };
            SkillsDone.Add(8002, 0);

            SkillAttributes[8003] = new ushort[2][];
            SkillAttributes[8003][0] = new ushort[6] { 7, 0, 0, 0, 0, 0 };
            SkillAttributes[8003][1] = new ushort[6] { 7, 0, 0, 0, 0, 0 };
            SkillsDone.Add(8003, 0);

            SkillAttributes[1320] = new ushort[3][];
            SkillAttributes[1320][0] = new ushort[6] { 2, 0, 0, 480, 255, 0 };
            SkillAttributes[1320][1] = new ushort[6] { 2, 0, 0, 1950, 255, 0 };
            SkillAttributes[1320][2] = new ushort[6] { 2, 0, 0, 5890, 255, 0 };
            SkillsDone.Add(1320, 2);

            SkillAttributes[1095] = new ushort[5][];
            SkillAttributes[1095][0] = new ushort[6] { 8, 0, 0, 0, 0, 0 };
            SkillAttributes[1095][1] = new ushort[6] { 8, 0, 0, 0, 0, 0 };
            SkillAttributes[1095][2] = new ushort[6] { 8, 0, 0, 0, 0, 0 };
            SkillAttributes[1095][3] = new ushort[6] { 8, 0, 0, 0, 0, 0 };
            SkillAttributes[1095][4] = new ushort[6] { 8, 0, 0, 0, 0, 0 };
            SkillsDone.Add(1095, 4);

            SkillAttributes[1000] = new ushort[5][];
            SkillAttributes[1000][0] = new ushort[6] { 2, 2, 0, 7, 15, 0 };
            SkillAttributes[1000][1] = new ushort[6] { 2, 2, 0, 16, 35, 0 };
            SkillAttributes[1000][2] = new ushort[6] { 2, 3, 0, 32, 50, 0 };
            SkillAttributes[1000][3] = new ushort[6] { 2, 4, 0, 57, 60, 0 };
            SkillAttributes[1000][4] = new ushort[6] { 2, 4, 0, 86, 65, 0 };
            SkillsDone.Add(1000, 4);

            SkillAttributes[1001] = new ushort[4][];
            SkillAttributes[1001][0] = new ushort[6] { 2, 0, 0, 130, 0, 0 };
            SkillAttributes[1001][1] = new ushort[6] { 2, 0, 0, 189, 0, 0 };
            SkillAttributes[1001][2] = new ushort[6] { 2, 0, 0, 275, 0, 0 };
            SkillAttributes[1001][3] = new ushort[6] { 2, 0, 0, 380, 0, 0 };
            SkillsDone.Add(1001, 3);

            SkillAttributes[1150] = new ushort[8][];
            SkillAttributes[1150][0] = new ushort[6] { 2, 0, 0, 378, 0, 0 };
            SkillAttributes[1150][1] = new ushort[6] { 2, 0, 0, 550, 0, 0 };
            SkillAttributes[1150][2] = new ushort[6] { 2, 0, 0, 760, 0, 0 };
            SkillAttributes[1150][3] = new ushort[6] { 2, 0, 0, 1010, 0, 0 };
            SkillAttributes[1150][4] = new ushort[6] { 2, 0, 0, 1332, 0, 0 };
            SkillAttributes[1150][5] = new ushort[6] { 2, 0, 0, 1764, 0, 0 };
            SkillAttributes[1150][6] = new ushort[6] { 2, 0, 0, 2332, 0, 0 };
            SkillAttributes[1150][7] = new ushort[6] { 2, 0, 0, 2800, 0, 0 };
            SkillsDone.Add(1150, 7);

            SkillAttributes[1180] = new ushort[8][];
            SkillAttributes[1180][0] = new ushort[6] { 2, 0, 0, 760, 0, 0 };
            SkillAttributes[1180][1] = new ushort[6] { 2, 0, 0, 1040, 0, 0 };
            SkillAttributes[1180][2] = new ushort[6] { 2, 0, 0, 1250, 0, 0 };
            SkillAttributes[1180][3] = new ushort[6] { 2, 0, 0, 1480, 0, 0 };
            SkillAttributes[1180][4] = new ushort[6] { 2, 0, 0, 1810, 0, 0 };
            SkillAttributes[1180][5] = new ushort[6] { 2, 0, 0, 2210, 0, 0 };
            SkillAttributes[1180][6] = new ushort[6] { 2, 0, 0, 2700, 0, 0 };
            SkillAttributes[1180][7] = new ushort[6] { 2, 0, 0, 3250, 0, 0 };
            SkillsDone.Add(1180, 7);

            SkillAttributes[1160] = new ushort[4][];
            SkillAttributes[1160][0] = new ushort[6] { 2, 0, 0, 855, 0, 0 };
            SkillAttributes[1160][1] = new ushort[6] { 2, 0, 0, 1498, 0, 0 };
            SkillAttributes[1160][2] = new ushort[6] { 2, 0, 0, 1985, 0, 0 };
            SkillAttributes[1160][3] = new ushort[6] { 2, 0, 0, 2623, 0, 0 };
            SkillsDone.Add(1160, 3);

            SkillAttributes[1010] = new ushort[1][];
            SkillAttributes[1010][0] = new ushort[6] { 3, 5, 0, 50, 0, 1 };
            SkillsDone.Add(1010, 0);

            SkillAttributes[1125] = new ushort[1][];
            SkillAttributes[1125][0] = new ushort[6] { 3, 8, 0, 300, 0, 1 };
            SkillsDone.Add(1125, 0);

            SkillAttributes[5001] = new ushort[1][];
            SkillAttributes[5001][0] = new ushort[6] { 1, 14, 0, 450, 0, 1 };
            SkillsDone.Add(5001, 0);

            SkillAttributes[1100] = new ushort[1][];
            SkillAttributes[1100][0] = new ushort[6] { 8, 0, 0, 0, 0, 0 };
            SkillsDone.Add(1100, 0);

            SkillAttributes[8000] = new ushort[6][];
            SkillAttributes[8000][0] = new ushort[6] { 13, 8, 0, 150, 100, 0 };
            SkillAttributes[8000][1] = new ushort[6] { 13, 8, 0, 180, 100, 0 };
            SkillAttributes[8000][2] = new ushort[6] { 13, 8, 0, 210, 100, 0 };
            SkillAttributes[8000][3] = new ushort[6] { 13, 8, 0, 240, 100, 0 };
            SkillAttributes[8000][4] = new ushort[6] { 13, 8, 0, 270, 100, 0 };
            SkillAttributes[8000][5] = new ushort[6] { 13, 8, 0, 300, 100, 0 };
            SkillsDone.Add(8000, 5);

            SkillAttributes[1175] = new ushort[5][];
            SkillAttributes[1175][0] = new ushort[6] { 6, 0, 0, 500, 0, 0 };
            SkillAttributes[1175][1] = new ushort[6] { 6, 0, 0, 600, 0, 0 };
            SkillAttributes[1175][2] = new ushort[6] { 6, 0, 0, 700, 0, 0 };
            SkillAttributes[1175][3] = new ushort[6] { 6, 0, 0, 800, 0, 0 };
            SkillAttributes[1175][4] = new ushort[6] { 6, 0, 0, 900, 0, 0 };
            SkillsDone.Add(1175, 4);

            SkillAttributes[5030] = new ushort[10][];
            SkillAttributes[5030][0] = new ushort[6] { 12, 0, 0, 115, 0, 33 };
            SkillAttributes[5030][1] = new ushort[6] { 12, 0, 0, 116, 0, 38 };
            SkillAttributes[5030][2] = new ushort[6] { 12, 0, 0, 117, 0, 43 };
            SkillAttributes[5030][3] = new ushort[6] { 12, 0, 0, 118, 0, 48 };
            SkillAttributes[5030][4] = new ushort[6] { 12, 0, 0, 119, 0, 53 };
            SkillAttributes[5030][5] = new ushort[6] { 12, 0, 0, 120, 0, 58 };
            SkillAttributes[5030][6] = new ushort[6] { 12, 0, 0, 121, 0, 63 };
            SkillAttributes[5030][7] = new ushort[6] { 12, 0, 0, 122, 0, 68 };
            SkillAttributes[5030][8] = new ushort[6] { 12, 0, 0, 123, 0, 73 };
            SkillAttributes[5030][9] = new ushort[6] { 12, 0, 0, 124, 0, 78 };
            SkillsDone.Add(5030, 9);
        }

        public static void RemoveFromFriend(uint RemoverUID, uint RemovedUID)
        {
            throw new NotImplementedException();
        }

        public static void LoadRevPoints()
        {
            RevPoints = new ushort[22][];
            RevPoints[0] = new ushort[4] { 1002, 1002, 430, 380 };
            RevPoints[1] = new ushort[4] { 1005, 1002, 430, 380 };
            RevPoints[2] = new ushort[4] { 1006, 1002, 430, 380 };
            RevPoints[3] = new ushort[4] { 1008, 1002, 430, 380 };
            RevPoints[4] = new ushort[4] { 1009, 1002, 430, 380 };
            RevPoints[5] = new ushort[4] { 1010, 1002, 430, 380 };
            RevPoints[6] = new ushort[4] { 1007, 1002, 430, 380 };
            RevPoints[7] = new ushort[4] { 1004, 1002, 430, 380 };
            RevPoints[8] = new ushort[4] { 1028, 1002, 430, 380 };
            RevPoints[9] = new ushort[4] { 1037, 1002, 430, 380 };
            RevPoints[10] = new ushort[4] { 1038, 1002, 438, 398 };
            RevPoints[11] = new ushort[4] { 1015, 1015, 717, 577 };
            RevPoints[12] = new ushort[4] { 1001, 1000, 499, 650 };
            RevPoints[13] = new ushort[4] { 1000, 1000, 499, 650 };
            RevPoints[14] = new ushort[4] { 1013, 1011, 193, 266 };
            RevPoints[15] = new ushort[4] { 1011, 1011, 193, 266 };
            RevPoints[16] = new ushort[4] { 1076, 1011, 193, 266 };
            RevPoints[17] = new ushort[4] { 1014, 1011, 193, 266 };
            RevPoints[18] = new ushort[4] { 1020, 1020, 566, 656 };
            RevPoints[19] = new ushort[4] { 1075, 1020, 566, 656 };
            RevPoints[20] = new ushort[4] { 1012, 1020, 566, 656 };
            RevPoints[21] = new ushort[4] { 6000, 6000, 50, 50 };
        }
        public static uint NeededSkillExp(short SkillId, byte Level)
        {
            if (SkillId == 1320)
            {
                if (Level == 0)
                    return 1500;
                if (Level == 1)
                    return 6000;
                else return 0;
            }
            else
                return 9999999;

        }

        public static uint NeededProfXP(byte Level)
        {
            if (Level == 1)
                return 1200;
            else if (Level == 2)
                return 68000;
            else if (Level == 3)
                return 250000;
            else if (Level == 4)
                return 640000;
            else if (Level == 5)
                return 1600000;
            else if (Level == 6)
                return 4000000;
            else if (Level == 7)
                return 10000000;
            else if (Level == 8)
                return 22000000;
            else if (Level == 9)
                return 40000000;
            else if (Level == 10)
                return 90000000;
            else if (Level == 11)
                return 95000000;
            else if (Level == 12)
                return 142500000;
            else if (Level == 13)
                return 213750000;
            else if (Level == 14)
                return 320625000;
            else if (Level == 15)
                return 480937500;
            else if (Level == 16)
                return 721406250;
            else if (Level == 17)
                return 1082109375;
            else if (Level == 18)
                return 1623164063;
            else if (Level > 18)
                return 2100000000;
            else
                return 0;
        }

        public static ulong NeededXP(uint Level)
        {
            if (Level == 1)
                return 39;
            else if (Level == 2)
                return 165;
            else if (Level == 3)
                return 165;
            else if (Level == 4)
                return 347;
            else if (Level == 5)
                return 627;
            else if (Level == 6)
                return 990;
            else if (Level == 7)
                return 1183;
            else if (Level == 8)
                return 2407;
            else if (Level == 9)
                return 3679;
            else if (Level == 10)
                return 8341;
            else if (Level == 11)
                return 11996;
            else if (Level == 12)
                return 14429;
            else if (Level == 13)
                return 18043;
            else if (Level == 14)
                return 21612;
            else if (Level == 15)
                return 22596;
            else if (Level == 16)
                return 32217;
            else if (Level == 17)
                return 37480;
            else if (Level == 18)
                return 47573;
            else if (Level == 19)
                return 56704;
            else if (Level == 20)
                return 68789;
            else if (Level == 21)
                return 70451;
            else if (Level == 22)
                return 75923;
            else if (Level == 23)
                return 97776;
            else if (Level == 24)
                return 114826;
            else if (Level == 25)
                return 120892;
            else if (Level == 26)
                return 123980;
            else if (Level == 27)
                return 126799;
            else if (Level == 28)
                return 145811;
            else if (Level == 29)
                return 173384;
            else if (Level == 30)
                return 197651;
            else if (Level == 31)
                return 202490;
            else if (Level == 32)
                return 212172;
            else if (Level == 33)
                return 244204;
            else if (Level == 34)
                return 285805;
            else if (Level == 35)
                return 305949;
            else if (Level == 36)
                return 312881;
            else if (Level == 37)
                return 324575;
            else if (Level == 38)
                return 366153;
            else if (Level == 39)
                return 434023;
            else if (Level == 40)
                return 460573;
            else if (Level == 41)
                return 506713;
            else if (Level == 42)
                return 570008;
            else if (Level == 43)
                return 728546;
            else if (Level == 44)
                return 850828;
            else if (Level == 45)
                return 916402;
            else if (Level == 46)
                return 935051;
            else if (Level == 47)
                return 940860;
            else if (Level == 48)
                return 1076590;
            else if (Level == 49)
                return 1272807;
            else if (Level == 50)
                return 1357986;
            else if (Level == 51)
                return 1384873;
            else if (Level == 52)
                return 1478420;
            else if (Level == 53)
                return 1632489;
            else if (Level == 54)
                return 1903121;
            else if (Level == 55)
                return 2065957;
            else if (Level == 56)
                return 2104909;
            else if (Level == 57)
                return 1921149;
            else if (Level == 58)
                return 2417153;
            else if (Level == 59)
                return 2853501;
            else if (Level == 60)
                return 3054580;
            else if (Level == 61)
                return 3111200;
            else if (Level == 62)
                return 3225607;
            else if (Level == 63)
                return 3811037;
            else if (Level == 64)
                return 4437965;
            else if (Level == 65)
                return 4880615;
            else if (Level == 66)
                return 4970959;
            else if (Level == 67)
                return 5107243;
            else if (Level == 68)
                return 5652526;
            else if (Level == 69)
                return 6579184;
            else if (Level == 70)
                return 6878005;
            else if (Level == 71)
                return 7100739;
            else if (Level == 72)
                return 7157642;
            else if (Level == 73)
                return 9106931;
            else if (Level == 74)
                return 10596415;
            else if (Level == 75)
                return 11220485;
            else if (Level == 76)
                return 11409179;
            else if (Level == 77)
                return 11424043;
            else if (Level == 78)
                return 12882966;
            else if (Level == 79)
                return 15172842;
            else if (Level == 80)
                return 15896985;
            else if (Level == 81)
                return 16163738;
            else if (Level == 82)
                return 16800069;
            else if (Level == 83)
                return 19230324;
            else if (Level == 84)
                return 22365189;
            else if (Level == 85)
                return 23819291;
            else if (Level == 86)
                return 24219524;
            else if (Level == 87)
                return 24864054;
            else if (Level == 88)
                return 27200095;
            else if (Level == 89)
                return 32033236;
            else if (Level == 90)
                return 33723786;
            else if (Level == 91)
                return 34291244;
            else if (Level == 92)
                return 34944017;
            else if (Level == 93)
                return 39463459;
            else if (Level == 94)
                return 45878550;
            else if (Level == 95)
                return 48924263;
            else if (Level == 96)
                return 49729242;
            else if (Level == 97)
                return 51072047;
            else if (Level == 98)
                return 55808382;
            else if (Level == 99)
                return 64870117;
            else if (Level == 100)
                return 68391872;
            else if (Level == 101)
                return 69537082;
            else if (Level == 102)
                return 76422949;
            else if (Level == 103)
                return 96950832;
            else if (Level == 104)
                return 112676761;
            else if (Level == 105)
                return 120090440;
            else if (Level == 106)
                return 121798300;
            else if (Level == 107)
                return 127680095;
            else if (Level == 108)
                return 137446904;
            else if (Level == 109)
                return 193716061;
            else if (Level == 110)
                return 408832135;
            else if (Level == 111)
                return 454674621;
            else if (Level == 112)
                return 461125840;
            else if (Level == 113)
                return 469189848;
            else if (Level == 114)
                return 477253857;
            else if (Level == 115)
                return 480479444;
            else if (Level == 116)
                return 485317884;
            else if (Level == 117)
                return 493381812;
            else if (Level == 118)
                return 580579979;
            else if (Level == 119)
                return 717424993;
            else if (Level == 120)
                return 282274071;
            else if (Level == 121)
                return 338728845;
            else if (Level == 122)
                return 406474656;
            else if (Level == 123)
                return 487769554;
            else if (Level == 124)
                return 585323469;
            else if (Level == 125)
                return 702388103;
            else if (Level == 126)
                return 842865806;
            else if (Level == 127)
                return 1011439064;
            else if (Level == 128)
                return 1073741808;
            else if (Level == 129)
                return 1073741759;
            else if (Level == 130)
                return 8737417590;
            else if (Level == 131)
                return 8737417590;
            else if (Level == 132)
                return 10037417590;
            else if (Level == 133)
                return 10837417590;
            else if (Level == 134)
                return 12437417590;
            else
                return 1;
        }

        public static void LoadGuilds()
        {
            throw new NotImplementedException();
        }

        public static void GetPlusInfo()
        {
            try
            {
                string[] PItem = File.ReadAllLines(DBPath + @"\ItemAdd.ini");
                DBPlusInfo = new string[PItem.Length][];
                for (int ik = 0; ik < PItem.Length; ik++)
                {
                    string[] a = PItem[ik].Split(' ');

                    DBPlusInfo[ik] = new string[10] { a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9] };
                }
                General.WriteLine("Plus information loaded.");
            }
            catch (Exception r) { Convert.ToString(r); }
        }

        public static void GetStats(Character Charr)
        {
            string str = "1";
            string agi = "1";
            string vit = "1";
            string Wis = "1";
            string lv;

            //if (Charr.Level > 130)
            //    lv = "130";
            //else
            //    lv = Convert.ToString(Charr.Level);
            /*
            if (Charr.Job == 50)
            {
                str = (Stats.ReadString("Heathen", "Strength[" + lv + "]"));
                agi = (Stats.ReadString("Heathen", "Agility[" + lv + "]"));
                vit = (Stats.ReadString("Heathen", "Vitality[" + lv + "]"));
                Wis = (Stats.ReadString("Heathen", "Wisrit[" + lv + "]"));
            }
            if (Charr.Job == 55)
            {
                str = (Stats.ReadString("Templar", "Strength[" + lv + "]"));
                agi = (Stats.ReadString("Templar", "Agility[" + lv + "]"));
                vit = (Stats.ReadString("Templar", "Vitality[" + lv + "]"));
                Wis = (Stats.ReadString("Templar", "Wisrit[" + lv + "]"));
            }
            if (Charr.Job > 9 && Charr.Job < 16)
            {
                str = (Stats.ReadString("Trojan", "Strength[" + lv + "]"));
                agi = (Stats.ReadString("Trojan", "Agility[" + lv + "]"));
                vit = (Stats.ReadString("Trojan", "Vitality[" + lv + "]"));
                Wis = (Stats.ReadString("Trojan", "Wisrit[" + lv + "]"));
            }
            if (Charr.Job > 19 && Charr.Job < 26)
            {
                str = (Stats.ReadString("Warrior", "Strength[" + lv + "]"));
                agi = (Stats.ReadString("Warrior", "Agility[" + lv + "]"));
                vit = (Stats.ReadString("Warrior", "Vitality[" + lv + "]"));
                Wis = (Stats.ReadString("Warrior", "Wisrit[" + lv + "]"));
            }
            if (Charr.Job > 39 && Charr.Job < 46)
            {
                str = (Stats.ReadString("Archer", "Strength[" + lv + "]"));
                agi = (Stats.ReadString("Archer", "Agility[" + lv + "]"));
                vit = (Stats.ReadString("Archer", "Vitality[" + lv + "]"));
                Wis = (Stats.ReadString("Archer", "Wisrit[" + lv + "]"));
            }
            if (Charr.Job > 129 && Charr.Job < 136 || Charr.Job > 139 && Charr.Job < 146 || Charr.Job == 100 || Charr.Job == 101)
            {
                str = (Stats.ReadString("Taoist", "Strength[" + lv + "]"));
                agi = (Stats.ReadString("Taoist", "Agility[" + lv + "]"));
                vit = (Stats.ReadString("Taoist", "Vitality[" + lv + "]"));
                Wis = (Stats.ReadString("Taoist", "Wisrit[" + lv + "]"));
            }
            */
            /*
            Charr.Str = ushort.Parse(str);
            Charr.Agi = ushort.Parse(agi);
            Charr.Vit = ushort.Parse(vit);
            Charr.Wis = ushort.Parse(Wis);*/
        }
        public static void LoadNpcs()
        {
            foreach (string file in Directory.GetFiles(DBPath + @"\cq_npc"))
            {
                try
                {
                    IniFile rdr = new IniFile(file);
                    Npc npc = new Npc();
                    npc.UID = Convert.ToUInt32(rdr.IniReadString("cq_npc", "id"));
                    npc.X = Convert.ToInt16(rdr.IniReadString("cq_npc", "cellx"));
                    npc.Y = Convert.ToInt16(rdr.IniReadString("cq_npc", "celly"));
                    npc.Map = Convert.ToInt16(rdr.IniReadString("cq_npc","mapid"));
                    npc.Type = Convert.ToUInt32(rdr.IniReadString("cq_npc","lookface"));
                    npc.Dir = Convert.ToByte(rdr.IniReadString("cq_npc", "type"));
                    npc.Flags = Convert.ToByte(rdr.IniReadString("cq_npc","type"));

                    Kernel.Npcs.Add(npc.UID, npc);
                }
                catch { }
            }
            Console.WriteLine("Npcs Loaded [{0}]", Kernel.Npcs.Count);
        }
        public static uint GetStatus(string Acc)
        {
            uint Return = 0;
            Ini Cli = new Ini(DBPath + @"\Accounts\\" + Acc + ".ini");
            Return = uint.Parse(Cli.ReadString("Account", "Status"));
            return Return;
        }
        public static void SpawnMobs()
        {
            foreach (MobSpawn spawn in Spawns.Values)
            {
                Mob ThisMob = new Mob();
                foreach (Mob mob in MobsToSpawn.Values)
                {
                    if (mob.ID == spawn.MobID)
                    {
                        ThisMob = mob;
                        break;
                    }
                }

                for (uint i = 0; i < spawn.SpawnAmount; i++)
                {
                    ThisMob.Pos = (byte)new Random().Next(0, 9);
                    ThisMob.UID = (uint)new Random().Next(400000, 500000);
                    while (Kernel.Mobs.ContainsKey(ThisMob.UID))
                        ThisMob.UID = (uint)new Random().Next(400000, 500000);
                    ThisMob.Map = (short)spawn.MapID;
                    //ThisMob.PosX = (short)General.Rand.Next(
                    //   Math.Min(spawn.X, spawn.Xc),
                    //   Math.Max(spawn.X, spawn.Xc));
                    //ThisMob.PosY = (short)General.Rand.Next(
                    //    Math.Min(spawn.Y, spawn.Yc),
                    //    Math.Max(spawn.Y, spawn.Yc));
                    try
                    {
                        ThisMob.PosX = (short)General.Rand.Next(spawn.X, spawn.Xc);
                        ThisMob.PosY = (short)General.Rand.Next(spawn.Y, spawn.Yc);
                    }
                    catch
                    {
                        ThisMob.PosX = (short)General.Rand.Next(spawn.Xc - 10, spawn.Xc);
                        ThisMob.PosY = (short)General.Rand.Next(spawn.Yc - 10, spawn.Yc);
                    }
                    ThisMob.Alive = true;
                    if (ThisMob.Name != null)
                    {
                        Kernel.Mobs.Add(ThisMob.UID, ThisMob);
                        Console.Title = "Loaded:" + Kernel.Mobs.Count;
                    }
                }
            }
            Console.WriteLine("Monsters Spawned [{0}]", Kernel.Mobs.Count);
            MobsToSpawn.Clear();
            Spawns.Clear();
        }
        public static Dictionary<uint, Mob> MobsToSpawn = new Dictionary<uint, Mob>();
        public static void LoadMobs()
        {
            IniFile cq_mob = new IniFile("");
            foreach (string file in Directory.GetFiles(DBPath + @"\cq_monstertype"))
            {
                try
                {
                    cq_mob.path=file;
                    Mob mob = new Mob();
                    mob.ID = Convert.ToUInt32(cq_mob.IniReadString("cq_monstertype", "id"));
                    mob.Name = Convert.ToString(cq_mob.IniReadString("cq_monstertype", "name"));
                    mob.Mech = Convert.ToInt32(cq_mob.IniReadString("cq_monstertype", "lookface"));
                    mob.CurHP = Convert.ToUInt32(cq_mob.IniReadString("cq_monstertype", "life"));
                    mob.MaxAtk = Convert.ToInt16(cq_mob.IniReadString("cq_monstertype", "attack_max"));
                    mob.MinAtk = Convert.ToInt16(cq_mob.IniReadString("cq_monstertype", "attack_min"));
                    mob.Dodge = Convert.ToByte(cq_mob.IniReadString("cq_monstertype", "dodge"));
                    mob.Level = Convert.ToByte(cq_mob.IniReadString("cq_monstertype", "level"));
                    mob.MType = Convert.ToByte(cq_mob.IniReadString("cq_monstertype", "magic_type"));
                    MobsToSpawn.Add(mob.ID, mob);
                }
                catch (Exception Exc)
                {
                    General.WriteLine(Convert.ToString(Exc));
                }
            }
            Console.WriteLine("Mobs Loaded");
        }
        public class MobSpawn
        {
            public uint SpawnID;
            public ushort MapID;
            public ushort X;
            public ushort Y;
            public ushort Xc;
            public ushort Yc;
            public uint MaxMobs;
            public ushort RestSecs;
            public uint SpawnAmount;
            public uint MobID;
        }
        public static Dictionary<uint, MobSpawn> Spawns = new Dictionary<uint, MobSpawn>();
        public static void LoadMobSpawns()
        {
            IniFile cq_gen = new IniFile("");
            foreach (string file in Directory.GetFiles(DBPath + @"\cq_generator"))
            {
                cq_gen.path = file;
                MobSpawn spawn = new MobSpawn();

                spawn.SpawnID = Convert.ToUInt32(cq_gen.IniReadString("cq_generator", "id"));
                spawn.MapID = Convert.ToUInt16(cq_gen.IniReadString("cq_generator", "mapid"));
                spawn.X =Convert.ToUInt16(cq_gen.IniReadString("cq_generator", "bound_x"));
                spawn.Y = Convert.ToUInt16(cq_gen.IniReadString("cq_generator", "bound_y"));
                spawn.Xc = Convert.ToUInt16(cq_gen.IniReadString("cq_generator", "bound_cx"));
                spawn.Yc = Convert.ToUInt16(cq_gen.IniReadString("cq_generator", "bould_cy"));
                spawn.MaxMobs = Convert.ToUInt32(cq_gen.IniReadString("cq_generator", "maxnpc"));
                spawn.RestSecs = Convert.ToUInt16(cq_gen.IniReadString("cq_generator", "rest_secs"));
                spawn.SpawnAmount = Convert.ToUInt32(cq_gen.IniReadString("cq_generator", "max_per_gen"));
                spawn.MobID =Convert.ToUInt32(cq_gen.IniReadString("cq_generator", "npctype"));
                Spawns.Add(spawn.SpawnID, spawn);
            }
            Console.WriteLine("Spawns Loaded");
        }
        public static void LoadItems()
        {
            string[] Ps = File.ReadAllLines(DBPath +@"\items.ini");
            Items = new uint[Ps.Length][];
            try
            {
                for (int i = 0; i < Ps.Length; i++)
                {
                    string[] PInfo = Ps[i].Split('-');
                    Items[i] = new uint[16] { uint.Parse(PInfo[0]), uint.Parse(PInfo[2]), uint.Parse(PInfo[3]), uint.Parse(PInfo[4]), uint.Parse(PInfo[5]), uint.Parse(PInfo[6]), uint.Parse(PInfo[7]), uint.Parse(PInfo[8]), uint.Parse(PInfo[9]), uint.Parse(PInfo[10]), uint.Parse(PInfo[11]), uint.Parse(PInfo[12]), uint.Parse(PInfo[13]), uint.Parse(PInfo[14]), uint.Parse(PInfo[15]), uint.Parse(PInfo[16]) };
                }
                Console.WriteLine("ITEMS: " + Ps.Length + " items successfully loaded.");
                Ps = null;
            }
            catch (Exception Exc) { General.WriteLine(Convert.ToString(Exc)); }
        }
        public static void LoadPortals()
        {
            string[] Ps = File.ReadAllLines(DBPath + @"\portals.ini");
            Portals = new ushort[Ps.Length][];
            int counter = 0;
            for (int i = 0; i < Ps.Length; i++)
            {
                string[] PInfo = Ps[i].Split('-');
                Portals[i] = new ushort[6];
                Portals[i][0] = ushort.Parse(PInfo[0]);
                Portals[i][1] = ushort.Parse(PInfo[1]);
                Portals[i][2] = ushort.Parse(PInfo[2]);
                Portals[i][3] = ushort.Parse(PInfo[3]);
                Portals[i][4] = ushort.Parse(PInfo[4]);
                Portals[i][5] = ushort.Parse(PInfo[5]);
                counter++;
            }
            Ps = null;
            Console.WriteLine("PORTALS: " + counter + " portals successfully loaded.");
        }
        public static Ini SyncedSave = new Ini("");
        public static void Save(Character Charr, string Key, object Value)
        {
            lock (SyncedSave)
            {
                SyncedSave.FileName = DBPath + @"\Characters\" + Charr.Name + ".ini";
                SyncedSave.Write("Character", Key, Value);
            }
        }
        public static void LogoutSave(Character Charr)
        {
            lock (SyncedSave)
            {
                SyncedSave.FileName = DBPath + @"\Characters\" + Charr.Name + ".ini";
                Charr.PackInventory();
                Charr.PackSkills();
                Charr.PackProfs();
                Charr.PackWarehouses();
                Charr.PackEnemies();
                Charr.PackFriends();
                Charr.PackEquips();
                SyncedSave.Write("Character", "Inv1", Convert.ToString(Charr.PackedInventory));
                SyncedSave.Write("Character", "TCWH1", Convert.ToString(Charr.PackedWHs));
                SyncedSave.Write("Character", "Skills", Charr.PackedSkills);
                SyncedSave.Write("Character", "Profs", Charr.PackedProfs);
                SyncedSave.Write("Character", "Warehouses", Charr.PackedWHs);
                SyncedSave.Write("Character", "Friends", Charr.PackedFriends);
                SyncedSave.Write("Character", "Enemies", Charr.PackedEnemies);
            }
        }
        public static void GetCharInfo(Character Character, string Acc)
        {
            try
            {
                Ini CN = new Ini(DBPath + @"\Accounts\" + Acc + ".ini");

                string CName = "";

                    if (Character.MyClient.CharacterUsage == 1)
                        CName = CN.ReadString("Account", "CharName1");
                    if (Character.MyClient.CharacterUsage == 2)
                        CName = CN.ReadString("Account", "CharName2");
                    if (Character.MyClient.CharacterUsage == 3)
                        CName = CN.ReadString("Account", "CharName3");
                    if (Character.MyClient.CharacterUsage == 4)
                        CName = CN.ReadString("Account", "CharName4");
                    if (Character.MyClient.CharacterUsage == 5)
                        CName = CN.ReadString("Account", "CharName5");

                Ini CharacterInfo = new Ini(DBPath + @"\Characters\" + CName + ".ini");
                Character.Name = CName;
                Character.Job = Convert.ToByte(CharacterInfo.ReadString("Character", "Job", "0"));
                Character.Level = Convert.ToByte(CharacterInfo.ReadString("Character", "Level", "1"));
                Character.Exp = Convert.ToUInt64(CharacterInfo.ReadString("Character", "Exp", "0"));
                Character.Model = Convert.ToUInt16(CharacterInfo.ReadString("Character", "Model", "1002"));
                Character.Avatar = Convert.ToByte(CharacterInfo.ReadString("Character", "Avatar", "0"));
                Character.Hair = Convert.ToUInt16(CharacterInfo.ReadString("Character", "Hair", "0"));
                Character.LocX = Convert.ToUInt16(CharacterInfo.ReadString("Character", "LocX", "400"));
                Character.LocY = Convert.ToUInt16(CharacterInfo.ReadString("Character", "LocY", "400"));
                Character.LocMap = Convert.ToUInt16(CharacterInfo.ReadString("Character", "LocMap", "1002"));
                Character.Str = Convert.ToUInt16(CharacterInfo.ReadString("Character", "Str", "0"));
                Character.Agi = Convert.ToUInt16(CharacterInfo.ReadString("Character", "Agi", "0"));
                Character.Vit = Convert.ToUInt16(CharacterInfo.ReadString("Character", "Vit", "0"));
                Character.Wis = Convert.ToUInt16(CharacterInfo.ReadString("Character", "Wis", "0"));
                Character.Dex = Convert.ToUInt16(CharacterInfo.ReadString("Character", "Dex", "0"));
                Character.Lck = Convert.ToUInt16(CharacterInfo.ReadString("Character", "Lck", "0"));
                Character.GrowthStr = Convert.ToUInt16(CharacterInfo.ReadString("Character", "GrowthStr", "0"));
                Character.GrowthAgi = Convert.ToUInt16(CharacterInfo.ReadString("Character", "GrowthAgi", "0"));
                Character.GrowthVit = Convert.ToUInt16(CharacterInfo.ReadString("Character", "GrowthVit", "0"));
                Character.GrowthWis = Convert.ToUInt16(CharacterInfo.ReadString("Character", "GrowthWis", "0"));
                Character.GrowthDex = Convert.ToUInt16(CharacterInfo.ReadString("Character", "GrowthDex", "0"));
                Character.GrowthLck = Convert.ToUInt16(CharacterInfo.ReadString("Character", "GrowthLck", "0"));
                Character.Silvers = Convert.ToUInt64(CharacterInfo.ReadString("Character", "Silvers", "0"));
                Character.CPs = Convert.ToUInt32(CharacterInfo.ReadString("Character", "CPs", "0"));
                Character.CurHP = Convert.ToUInt16(CharacterInfo.ReadString("Character", "CurHP", "0"));
                Character.CurMP = Convert.ToUInt16(CharacterInfo.ReadString("Character", "CurtMP", "0"));
                Character.PKPoints = Convert.ToUInt16(CharacterInfo.ReadString("Character", "PKPoints", "0"));
                Character.RBCount = Convert.ToByte(CharacterInfo.ReadString("Character", "RBCount", "0"));
                Character.PackedInventory = CharacterInfo.ReadString("Character", "Inv1", "0");
                Character.PackedWHs = CharacterInfo.ReadString("Character", "TCWH1", "0");
                Character.PackedEquips = CharacterInfo.ReadString("Character", "Equipment", "0");
                Character.PackedSkills = CharacterInfo.ReadString("Character", "Skills", "0");
                Character.PackedProfs = CharacterInfo.ReadString("Character", "Profs", "0");
                Character.WHSilvers = Convert.ToUInt64(CharacterInfo.ReadString("Character", "WHMoney", "0"));
                Character.PackedWHs = CharacterInfo.ReadString("Character", "Warehouses", "0");
                Character.PackedFriends = CharacterInfo.ReadString("Character", "Friends", "0");
                Character.PackedEnemies = CharacterInfo.ReadString("Character", "Enemies", "0");
                Character.VP = Convert.ToUInt32(CharacterInfo.ReadString("Character", "VP", "0"));
                Character.GuildDonation = Convert.ToUInt64(CharacterInfo.ReadString("Character", "GuildDonation", "0"));
                Character.GuildID = Convert.ToUInt16(CharacterInfo.ReadString("Character", "MyGuild", "0"));
                Character.GuildPosition = Convert.ToByte(CharacterInfo.ReadString("Character", "GuildPos", "0"));
                Character.PrevMap = Convert.ToUInt16(CharacterInfo.ReadString("Character", "PrevMap", "0"));
                if (Guilds.AllGuilds.Contains(Character.GuildID))
                    Character.MyGuild = (Guild)Guilds.AllGuilds[Character.GuildID];
                Character.MinAtk = Character.Str;
                Character.MaxAtk = Character.Str;
                Character.Potency = Character.Level;
                Character.RealModel = Character.Model;
                Character.RealAvatar = Character.Avatar;
                Character.MaxHP = Character.BaseMaxHP();
                //Character.MaxMP = Character.BaseMaxMP();
                Character.RealAgi = Character.Agi;
                Character.StatP = Convert.ToUInt16(CharacterInfo.ReadString("Character", "StatP", "0"));
            }
            catch (Exception Exc)
            {
                General.WriteLine(Convert.ToString(Exc));
            }
        }
        public static bool CreateCharacter(string Name, uint Class, uint Model, uint Avatar, Client UClient)
        {
            if (!File.Exists(DBPath + @"\Characters\" + Name + ".ini"))
            {
                Ini Create = new Ini(DBPath + @"\Characters\" + Name + ".ini");
                Ini AccChange = new Ini(DBPath + @"\Accounts\" + UClient.Account + ".ini");

                string str = "1";
                string agi = "1";
                string vit = "1";
                string Wis = "1";
                string Lck = "1";
                string Dex = "1";

                /*
                if (Class == 10)
                {
                    str = (Stats.ReadString("Trojan", "Strength[1]"));
                    agi = (Stats.ReadString("Trojan", "Agility[1]"));
                    vit = (Stats.ReadString("Trojan", "Vitality[1]"));
                    Wis = (Stats.ReadString("Trojan", "Wisrit[1]"));
                }
                if (Class == 50)
                {
                    str = (Stats.ReadString("Heathen", "Strength[1]"));
                    agi = (Stats.ReadString("Heathen", "Agility[1]"));
                    vit = (Stats.ReadString("Heathen", "Vitality[1]"));
                    Wis = (Stats.ReadString("Heathen", "Wisrit[1]"));
                }
                if (Class == 55)
                {
                    str = (Stats.ReadString("Templar", "Strength[1]"));
                    agi = (Stats.ReadString("Templar", "Agility[1]"));
                    vit = (Stats.ReadString("Templar", "Vitality[1]"));
                    Wis = (Stats.ReadString("Templar", "Wisrit[1]"));
                }
                if (Class == 20)
                {
                    str = (Stats.ReadString("Warrior", "Strength[1]"));
                    agi = (Stats.ReadString("Warrior", "Agility[1]"));
                    vit = (Stats.ReadString("Warrior", "Vitality[1]"));
                    Wis = (Stats.ReadString("Warrior", "Wisrit[1]"));
                }
                if (Class == 40)
                {
                    str = (Stats.ReadString("Archer", "Strength[1]"));
                    agi = (Stats.ReadString("Archer", "Agility[1]"));
                    vit = (Stats.ReadString("Archer", "Vitality[1]"));
                    Wis = (Stats.ReadString("Archer", "Wisrit[1]"));
                }
                if (Class == 100)
                {
                    str = (Stats.ReadString("Taoist", "Strength[1]"));
                    agi = (Stats.ReadString("Taoist", "Agility[1]"));
                    vit = (Stats.ReadString("Taoist", "Vitality[1]"));
                    Wis = (Stats.ReadString("Taoist", "Wisrit[1]"));
                }*/
                //ulong uid = (uint)General.Rand.Next(1000001, 19999999) + (uint)General.Rand.Next(1000001, 19999999) + (uint)General.Rand.Next(1000001, 19999999) / (uint)General.Rand.Next(1000, 19999);
                string mp = Convert.ToString(short.Parse(Wis) * 3);
                string hp = Convert.ToString((short.Parse(vit) * 24 + short.Parse(str) * 3 + short.Parse(agi) * 3 + short.Parse(Wis) * 3));

                Create.Write("Character", "Name", Name);
                Create.Write("Character", "Account", UClient.Account);
                Create.Write("Character", "Level", "1");
                Create.Write("Character", "Exp", "0");
                Create.Write("Character", "Str", str);
                Create.Write("Character", "Agi", agi);
                Create.Write("Character", "Vit", vit);
                Create.Write("Character", "Wis", Wis);
                Create.Write("Character", "Lck", Lck);
                Create.Write("Character", "Dex", Dex);
                Create.Write("Character", "GrowthStr", "1");
                Create.Write("Character", "GrowthAgi", "1");
                Create.Write("Character", "GrowthVit", "1");
                Create.Write("Character", "GrowthWis", "1");
                Create.Write("Character", "GrowthLck", "1");
                Create.Write("Character", "GrowthDex", "1");
                Create.Write("Character", "Job", Convert.ToString(Class));
                Create.Write("Character", "Model", Convert.ToString(Model));
                Create.Write("Character", "Silvers", "100");
                Create.Write("Character", "CPs", "0");
                Create.Write("Character", "Karma", "0");
                Create.Write("Character", "CurHP", hp);
                Create.Write("Character", "CurMP", mp);
                Create.Write("Character", "StatP", "0");
                Create.Write("Character", "LocMap", "1002");
                Create.Write("Character", "LocX", "438");
                Create.Write("Character", "LocY", "377");
                Create.Write("Character", "Hair", "410");
                Create.Write("Character", "Inv1", "");
                Create.Write("Character", "PKPoints", "0");
                Create.Write("Character", "Skills", "");
                Create.Write("Character", "Profs", "");
                Create.Write("Character", "RBCount", "0");
                Create.Write("Character", "Avatar", "1");
                Create.Write("Character", "WHSilvers", "0");
                Create.Write("Character", "Warehouses", ":::::");
                Create.Write("Character", "VP", "0");
                Create.Write("Character", "Friends", "");
                Create.Write("Character", "Enemies", "");
                Create.Write("Character", "GuildDonation", "0");
                Create.Write("Character", "MyGuild", "0");
                Create.Write("Character", "GuildPos", "0");
                Create.Write("Character", "PrevMap", "0"); ;

                AccChange.Write("Account", "LogonType", "1");

                if (UClient.CharacterUsage == 1)
                    AccChange.Write("Account", "CharName1", Name);
                if (UClient.CharacterUsage == 2)
                    AccChange.Write("Account", "CharName2", Name);
                if (UClient.CharacterUsage == 3)
                    AccChange.Write("Account", "CharName3", Name);
                if (UClient.CharacterUsage == 4)
                    AccChange.Write("Account", "CharName4", Name);
                if (UClient.CharacterUsage == 5)
                    AccChange.Write("Account", "CharName5", Name);
                return true;
            }
            else return false;
        }
    }
}